<template>
  <div>
    <el-table :data="tableData" style="width: 100%" max-height="400">
      <el-table-column fixed prop="id" label="编号" width="150">
      </el-table-column>
      <el-table-column prop="userId" label="用户ID" width="120">
      </el-table-column>
      <el-table-column prop="userName" label="姓名" width="120">
      </el-table-column>
      <el-table-column prop="account" label="账号" width="120">
      </el-table-column>
      <el-table-column prop="loginDate" label="登入时间" width="300">
      </el-table-column>
      <el-table-column prop="browser" label="浏览器名称" width="120">
      </el-table-column>
      <el-table-column prop="operatingSystem" label="操作系统" width="120">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNum"
        :page-sizes="[5, 15, 30]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [], //结果集
      page: {
        //分页条件
        pageNum: 1,
        pageSize: 5,
        search: {},
      },
      total: 0, //总数量
    };
  },
  created() {
    this.findLoginLog();
  },
  methods: {
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.findLoginLog();
    },
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.findLoginLog();
    },
    /**
     * 分页条件查询登入日志
     */
    async findLoginLog() {
      await fetch("/api/auth/pd_common_login_log/findLoginLog", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify(this.page),
      })
        .then((response) => response.json())
        .then((data) => {
          this.tableData = data.data.list;
          this.total = data.data.total;
        });
    },
  },
};
</script>
<style>
.block {
  text-align: center;
  margin-top: 40px;
}
</style>
